const express = require('express');
const exphbs = require('express-handlebars');
const hbs = exphbs.create({
    // 用来支持 模板中 的计算相关
    helpers:{
        multiply:function(a,b){
            return a * b;
        },
        increase:function(value){
            return value+1
        }
    }
})
const app = express();
app.engine('handlebars',hbs.engine);
// 设置后缀
app.set('view engine','handlebars');
//指定模板的存放目录
app.set('views','./views');

// 树结构数据
const treeData = [
    {
        name:'parent1',
        children:[
            {
                name:'parent1-children1',
                children:[
                    {
                        name:'parent1-children1-children1',
                        children:[]
                    }
                ]
            },
            {
                name:'parent1-children2',
                children:[]
            },
        ]
    }
]

app.get('/',(req,res)=>{
    res.render('home',{title:"home"});
})

app.get('/tree',(req,res)=>{
    res.render('tree',{treeData});
})
app.listen(8081)